package cn.wolfcode.luowowo.website.util;

import cn.wolfcode.luowowo.cache.util.RedisKeys;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieUtil {
    public static String getToken(HttpServletResponse response, HttpServletRequest request) {
        //获取cookie
        Cookie[] cookies = request.getCookies();
        //判断是否存在cookie
        String token = "";
        if (cookies != null && cookies.length > 0) {
            for (Cookie cookie : cookies) {
                String name = cookie.getName();
                if ("token".equals(name)) {
                    cookie.setMaxAge(RedisKeys.USER_LOGIN.getTime().intValue());
                    cookie.setPath("/");
                    response.addCookie(cookie);
                    return cookie.getValue();
                }

            }
        }
        return null;

    }
}
